package com.demo;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo3Thread {
    public static boolean flag = false;

    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                10, 20, 1, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                new ThreadPoolExecutor.AbortPolicy()
        );

        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {

            }
        });


        /*MyThread myThread=new MyThread();
        myThread.start();*/

//        CountDownLatch c0 = new CountDownLatch(0); //计数器为0
//        CountDownLatch c1 = new CountDownLatch(1); //计数器为1
//        CountDownLatch c2 = new CountDownLatch(1); //计数器为1
//
//        Thread t1 = new Thread(new MyRunnable(c2, c2), "a");
//
//        Thread t2 = new Thread(new MyRunnable(c0, c1), "b");
//
//        Thread t3 = new Thread(new MyRunnable(c1, c2), "c");
//
//        // t1.start();
//        //  t3.start();
//        t2.start();


    }
}

class Pserson {
    static int count = 0;
    private int n;

    public Pserson() {
        n = count++;
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }
}

class MyThread extends Thread {
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName());
    }
}

class MyRunnable implements Runnable {

    private CountDownLatch x;
    private CountDownLatch y;

    public MyRunnable(CountDownLatch x, CountDownLatch y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public void run() {
        try {

            x.await();
            y.countDown();
            y.countDown();
            System.out.println(Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }


}

